/**************************************************************************
 *
 * Copyright (c) 2015-2017  QIKU Company             　　　　　　　            
 *                 奇酷软件（深圳）有限公司  版权所有 2015-2017
 *
 * PROPRIETARY RIGHTS of QIKU Company are involved in the  　　　　　　     
 * subject matter of this material.  All manufacturing, reproduction, use, 
 * and sales rights pertaining to this subject matter are governed by the  
 * license agreement.  The recipient of this software implicitly accepts   
 * the terms of the license.                                               
 * 本软件文档资料是奇酷公司的资产,任何人士阅读和使用本资料必须获得                     
 * 相应的书面授权,承担保密责任和接受相应的法律约束.                                 
 *
 **************************************************************************/
package com.yw.android.common.utils;

import android.util.Log;

import com.yw.android.common.Init;
import com.yw.android.common.Release;

/**
 * 日志
 *
 * @author yuanwei
 */
public class LOG {
    /**
     * 日志等级
     */
    public final static int D = Log.DEBUG;    // DEBUG 级别
    public final static int I = Log.INFO;     // INFO 级别
    public final static int W = Log.WARN;     // WARN 级别
    public final static int E = Log.ERROR;    // ERROR 级别
    /**
     * 日志标签
     */
    private static String stag = "YW";

    static {
        try {
            stag = Init.getLogTag();
        } catch (Throwable t) {
            Log.w("YW", "init log tag failed: " + t
                    + "\n    maybe you need instance 'Init'");
        }
    }

    /**
     * 设置日志等级
     *
     * @param level 日志等级
     */
    public static void setLevel(int level) {
    }

    /**
     * 设置日志标签
     *
     * @param tag 日志标签
     */
    public static void setTag(String tag) {
        Log.i("LOG", "[" + stag + "] set log tag to " + tag);
        stag = tag;
    }

    /**
     * 打印日志，DEBUG级别
     *
     * @param msg 日志消息
     */
    public static void d(String msg) {
        if (!Release.DEBUG) return;
        StackTraceElement stackTrace = Thread.currentThread().getStackTrace()[3];
        String fileInfo = stackTrace.getFileName() + "(" + stackTrace.getLineNumber() + ") " + stackTrace.getMethodName();
        Log.d(stag, "[Thread:" + Thread.currentThread().getName() + "][fileInfo:" + fileInfo + "] " + msg);
    }

    /**
     * 打印日志，DEBUG级别
     *
     * @param msg 日志消息
     * @param t   异常对象
     */
    public static void d(String msg, Throwable t) {
        if (!Release.DEBUG) return;
        StackTraceElement stackTrace = Thread.currentThread().getStackTrace()[3];
        String fileInfo = stackTrace.getFileName() + "(" + stackTrace.getLineNumber() + ") " + stackTrace.getMethodName();
        Log.d(stag, "[Thread:" + Thread.currentThread().getName() + "][fileInfo:" + fileInfo + "] " + msg, t);
    }

    /**
     * 打印日志，INFO级别
     *
     * @param msg 日志消息
     */
    public static void i(String msg) {
        if (!Release.DEBUG) return;
        StackTraceElement stackTrace = Thread.currentThread().getStackTrace()[3];
        String fileInfo = stackTrace.getFileName() + "(" + stackTrace.getLineNumber() + ") " + stackTrace.getMethodName();
        Log.i(stag, "[Thread:" + Thread.currentThread().getName() + "][fileInfo:" + fileInfo + "] " + msg);
    }

    /**
     * 打印日志，INFO级别
     *
     * @param msg 日志消息
     * @param t   异常对象
     */
    public static void i(String msg, Throwable t) {
        if (!Release.DEBUG) return;
        StackTraceElement stackTrace = Thread.currentThread().getStackTrace()[3];
        String fileInfo = stackTrace.getFileName() + "(" + stackTrace.getLineNumber() + ") " + stackTrace.getMethodName();
        Log.i(stag, "[Thread:" + Thread.currentThread().getName() + "][fileInfo:" + fileInfo + "] " + msg, t);
    }

    /**
     * 打印日志，WARN级别
     *
     * @param msg 日志消息
     */
    public static void w(String msg) {
        if (!Release.DEBUG) return;
        StackTraceElement stackTrace = Thread.currentThread().getStackTrace()[3];
        String fileInfo = stackTrace.getFileName() + "(" + stackTrace.getLineNumber() + ") " + stackTrace.getMethodName();
        Log.w(stag, "[Thread:" + Thread.currentThread().getName() + "][fileInfo:" + fileInfo + "] " + msg);
    }

    /**
     * 打印日志，WARN级别
     *
     * @param msg 日志消息
     * @param t   异常对象
     */
    public static void w(String msg, Throwable t) {
        if (!Release.DEBUG) return;
        StackTraceElement stackTrace = Thread.currentThread().getStackTrace()[3];
        String fileInfo = stackTrace.getFileName() + "(" + stackTrace.getLineNumber() + ") " + stackTrace.getMethodName();
        Log.w(stag, "[Thread:" + Thread.currentThread().getName() + "][fileInfo:" + fileInfo + "] " + msg, t);
    }

    /**
     * 打印日志，ERROR级别
     *
     * @param msg 日志消息
     */
    public static void e(String msg) {
        if (!Release.DEBUG) return;
        StackTraceElement stackTrace = Thread.currentThread().getStackTrace()[3];
        String fileInfo = stackTrace.getFileName() + "(" + stackTrace.getLineNumber() + ") " + stackTrace.getMethodName();
        Log.e(stag, "[Thread:" + Thread.currentThread().getName() + "][fileInfo:" + fileInfo + "] " + msg);
    }

    /**
     * 打印日志，ERROR级别
     *
     * @param msg 日志消息
     * @param t   异常对象
     */
    public static void e(String msg, Throwable t) {
        if (!Release.DEBUG) return;
        StackTraceElement stackTrace = Thread.currentThread().getStackTrace()[3];
        String fileInfo = stackTrace.getFileName() + "(" + stackTrace.getLineNumber() + ") " + stackTrace.getMethodName();
        Log.e(stag, "[Thread:" + Thread.currentThread().getName() + "][fileInfo:" + fileInfo + "] " + msg, t);
    }
}
